package com.zzh.custom.loading.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

import com.zzh.custom.R;
import com.zzh.custom.loading.LoadingTag;

public class MyLinearLayout extends LinearLayout implements LoadingTag {
    public MyLinearLayout(Context context) {
        super(context);
        init(context,null,0,0);
    }

    public MyLinearLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context,attrs,0,0);
    }

    public MyLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context,attrs,defStyleAttr,0);
    }

    public MyLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context,attrs,defStyleAttr,defStyleRes);
    }

    private boolean mIsAllowOngoing;

    private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        if (attrs == null) return;
        TypedArray typeArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.LoadingView, defStyleAttr, defStyleRes);
        mIsAllowOngoing = typeArray.getBoolean(R.styleable.LoadingView_loadingAllowOngoing, false);
        typeArray.recycle();
    }

    @Override
    public boolean isAllowOngoing() {
        return mIsAllowOngoing;
    }
}
